<template>
	<view class="main-content-frame u-flex-col">
		<view class="u-flex-1 u-padding-left-30 u-padding-right-30">
			<u-form :model="form" ref="uForm">
				<u-form-item :border-bottom="false" :label-width="220" :required="true" label="合作需求类型">
					<u-input @click="selectShowStatus = true" v-model="type" type="select" input-align="right"
						placeholder="请选择合作类型" />
				</u-form-item>
				<view v-if="form.type == 1" class="">
					<view class="xl bold">
						产品信息
					</view>
					<u-form-item :border-bottom="false" :label-width="220" :required="true" label="产品名称">
						<u-input v-model="form.name" input-align="right" placeholder="请输入产品名称" />
					</u-form-item>
					<u-form-item :border-bottom="false" :label-width="220" :required="true" label="产品月息">
						<u-input v-model="form.interests" input-align="right" placeholder="请输入产品月息" />
					</u-form-item>
					<u-form-item :border-bottom="false" :label-width="220" :required="true" label="产品额度">
						<u-input v-model="form.quota" input-align="right" placeholder="请输入产品额度" />
						<text class="nr u-padding-left-10">万</text>
					</u-form-item>
					<u-form-item :border-bottom="false" label-position="top" :label-width="220" :required="true"
						label="产品优势描述">
						<u-input v-model="form.describe" type="textarea" placeholder="请输入产品优势描述" :custom-style="{
									padding: '20rpx',
									borderRadius: '8rpx',
									background: '#FAFAFA'
								}" />
					</u-form-item>
					<view class="xl bold">
						合作需求
					</view>
				</view>
				<u-form-item :border-bottom="false" label-position="top" :label-width="220" label="">
					<u-input v-model="form.demand" type="textarea" placeholder="点击此处编辑您的合作需求" :custom-style="{
								padding: '20rpx',
								borderRadius: '8rpx',
								background: '#FAFAFA'
							}" />
				</u-form-item>
			</u-form>
			<view class="xs hint-area u-padding-15 u-border-radius-10">
				温馨提示：平台会对发布的需求进行审核，审核通过后即可在合作需求列表中显示
			</view>
		</view>
		<view class="footer-area">
			<u-button @click="saveDatasValidate" shape="circle" hover-class="none" :custom-style="{
				width: '70%',
				color: '#FFF',
				margin: '4vh 15%',
				background: 'linear-gradient(180deg, #6BB2FF 0%, #437EEA 100%)'
			}">保存</u-button>
		</view>
		<u-select v-model="selectShowStatus" mode="single-column" :list="list"
			@confirm="(e)=>{form.type = e[0].value;type = e[0].label;}"></u-select>
	</view>
</template>

<script>
	import {
		publishCooperation
	} from "@/yixu/api/network_square"
	export default {
		data() {
			return {
				type: '其他合作',
				form: {
					type: 2
				},
				product: {},
				selectShowStatus: false,
				list: [{
						value: '1',
						label: '产品合作'
					},
					{
						value: '2',
						label: '其他合作'
					}
				]
			}
		},
		onLoad({edit,id}) {
			if(edit){
				let item = uni.getStorageSync('cooperation_item');
				this.form.id = item.id;
				this.form.type = item.type;
				this.type = this.list.find(citem=>citem.value == item.type).label;
				this.form.name = item.product_name;
				this.form.interests = item.interests;
				this.form.quota = item.quota;
				this.form.describe = item.describe;
				this.form.demand = item.demand;
			}
		},
		methods:{
			async saveDatasValidate(){
				let _this = this;
				if(_this.form.type == 1){
					let rules = {
						name :'请输入产品名称',
						interests :'请输入产品月息',
						quota :'请输入产品额度',
						describe :'请输入产品优势描述',
					}
					try{
						for (let key in rules) {
							if(_this.$u.test.isEmpty(_this.form[key])){
								throw new Error(rules[key])
							}
						}
					}catch(e){
						return _this.$u.toast(e.message);
					}
				}
				
				uni.showLoading({
					title: '数据上传中...',
					mask: true
				});
				
				let {
					code,
					msg
				} = await publishCooperation({
					..._this.form
				})
				uni.hideLoading();
				
				_this.$u.toast(msg);
				
				setTimeout(()=>{
					uni.redirectTo({
						url:'/yixu/pages/network_square/my_business_card/index'
					})
				},800)
			}
		}
	}
</script>

<style lang="scss">
	page {
		background: #FFF;

		.main-content-frame {
			min-height: 100vh;
		}

		.hint-area {
			color: #FF7D00;
			background: #FFF7E8;
		}
	}
</style>